import json
import packer
import utils
import random
import sys

print ("Hello, tourist! It is the knapsack packing system prototype\n")

# read pool of items from file in JSON format
f = open('./pool.js', 'r')
pool = f.read()
f.close

# JSON decode pool
pool = json.loads(pool)

# packing (pack this fucking stuff!)

for i in range(2, len(pool)):
    print (i+1, "items ")
    pool2 = pool[0:i+1]
    tot = 0.0
    for i in pool2:
        tot += i["weight"]
    maximum = random.randrange(0, tot)
#     print ("max =", maximum)
#     print (pool2)

    knapsack = packer.genetic(pool2, maximum)
    print ("Genetic, Result: ")
    utils.show(knapsack)                      
    
    knapsack = packer.bb(pool2, maximum)
    print ("Brench and bound, Result: ")
    utils.show(knapsack)
    
    print ("\n\n\n")

# knapsack = packer.wrongbb(pool, 10000)
# print ("WRONG approach to brench and bound, Result: ")
# utils.show(knapsack)
     

print ("Your knapsack is ready, take it!")
